package example.pattern.observer;

import java.util.Vector;

/**
 * subject class
 * 
 * @author Administrator
 *
 */
public class NumberGenerator {
	Vector<Observer> observers = new Vector<Observer>();
	
	
	public int generateNumber() {
		int number = new java.util.Random().nextInt(40);
		notify(number);
		return number;
	}

	public void addObserver(Observer observer){
		observers.add(observer);
	}
	
	public void removeObserver(Observer observer){
		observers.remove(observer);
	}
	
	private void notify(int number){
		for(Observer observer:observers){
			observer.notify(number);
		}
	}

}
